﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;
using System.IO;
using System.Drawing.Imaging;

namespace DisplayBoardInfo.Server.Helpers
{
    class Convert
    {
        public static string GetDayOfWeek(int day)
        {
            switch (day)
            { 
                case 1 :
                    return "Poniedziałek";
                case 2 :
                    return "Wtorek";
                case 3:
                    return "Środa";
                case 4:
                    return "Czwartek";
                case 5:
                    return "Piątek";
                case 6:
                    return "Sobota";
                case 7:
                    return "Niedziela";
                default:
                    return "-";
            }
        }

        public static string GetDayOfWeek(DayOfWeek day)
        {
            switch (day)
            {
                case DayOfWeek.Monday:
                    return "Poniedziałek";
                case DayOfWeek.Tuesday:
                    return "Wtorek";
                case DayOfWeek.Wednesday:
                    return "Środa";
                case DayOfWeek.Thursday:
                    return "Czwartek";
                case DayOfWeek.Friday:
                    return "Piątek";
                case DayOfWeek.Saturday:
                    return "Sobota";
                case DayOfWeek.Sunday:
                    return "Niedziela";
                default:
                    return "-";
            }
        }

        public static BitmapImage ImageToBitmapImage(System.Drawing.Image image)
        {
            System.Drawing.Bitmap b = new System.Drawing.Bitmap(image); 
            BitmapImage bi = new BitmapImage();

            bi.BeginInit();

            MemoryStream ms = new MemoryStream();

            b.Save(ms, ImageFormat.Bmp);

            ms.Seek(0, SeekOrigin.Begin);

            bi.StreamSource = ms;

            bi.EndInit();

            return bi;
        }

        public static string NumbersToString(int number)
        {
            if (number < 10) return "0" + number.ToString();
            else return number.ToString();
        }

        #region EntitiesToNetwork

        public static Network.Messages.Content.User FromEntityToNetworkEntity(Entities.User user)
        {
            Network.Messages.Content.User output = new Network.Messages.Content.User();
            output.Lastname = user.LastName;
            output.Name = user.Name;
            output.Password = user.Password;
            output.Role = user.Role.Name;
            output.Username = user.Username;

            return output;
        }

        public static Network.Messages.Content.Patient FromEntityToNetworkEntity(Entities.Patient patient)
        {
            Network.Messages.Content.Patient output = new Network.Messages.Content.Patient();
            output.ID = patient.ID;
            output.LastName = patient.LastName;
            output.Name = patient.Name;
            output.PESEL = patient.PESEL;

            return output;
        }

        public static Network.Messages.Content.Appointment FromEntityToNetworkEntity(Entities.Appointment appointment)
        {
            Network.Messages.Content.Appointment output = new Network.Messages.Content.Appointment();
            output.Date = appointment.DateTime;
            output.Doctor = FromEntityToNetworkEntity(appointment.Doctor);
            output.ExpectedTime = appointment.Time == null ? 0 : (int)appointment.Time;
            output.ID = appointment.ID;
            output.Number = appointment.Number == null ? 0 : (int)appointment.Number;
            output.Patient = FromEntityToNetworkEntity(appointment.Patient);

            return output;
        }

        #endregion
    }
}
